package com.vichat.common.threads;

import com.vichat.common.signal.SignalCmdUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;

public class RefreshDataThread implements Runnable {

    private static Logger logger = LoggerFactory.getLogger(RefreshDataThread.class);

    private String key;
    private String[] ids;
    private String adminCmd;

    public RefreshDataThread(String key, String[] ids, String adminCmd) {
        this.key = key;
        this.ids = ids;
        this.adminCmd = adminCmd;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(3000);
            try {
                if ("uid".equals(key)) {
                    SignalCmdUtil.refreshData(null, ids, adminCmd);
                } else if ("rid".equals(key)) {
                    SignalCmdUtil.refreshData(ids, null, adminCmd);
                }
            } catch (Exception ee) {
                String errmsg = "refresh_data_failed>>>>>>> param:key=" + key + ",id=" + Arrays.asList(ids).toString();
                logger.error(errmsg, ee);
            }
        } catch (Exception e) {
            logger.error("refresh_data_error>>>>>>" + e.getMessage(), e);
        }
    }

    public static void main(String[] args) {
        SignalCmdUtil.initSignalClient();
        String[] data = "140008".split(",");
        new RefreshDataThread("uid", data, "refresh_data").run();
    }

}
